<?php
namespace app\admin\controller\openservice;
use app\common\controller\Admin;
use app\common\traits\ControllerCurd;
use app\common\annotation\NodeAnnotation;
use think\Request;

/**
 * Class Index
 * @NodeAnnotation(
 *     title="开放类别",
 *     parent="admin/openservice.index",
 *     is_menu=0,
 *     is_view=0,
 * )
 */
class Servicecategory extends Admin
{
    use ControllerCurd;
    public $model ;
    public function initialize()
    {
        parent::initialize();
        $this->model = new \app\admin\model\openservice\ServiceCategory();
    }

    /**
     * @NodeAnnotation(
     *     title="开放类别",
     *     parent="admin/openservice.servicecategory",
     *     MenuRoot="admin/openservice.index"
     * )
     */
    public function index(Request $request)
    {
        $keywords  = $request->param("keywords");

        $where = [];

        if($keywords) array_push($where,['service_name',"like","%$keywords%"]);

        $this->assign([
            "serviceList" => $this->model->where($where)->paginate(),
            "search" => [
                "keywords" => $keywords
            ]
        ]);
        return $this->fetch();
    }

    /**
     * @NodeAnnotation(
     *     title="添加开放类别",
     *     parent="admin/openservice.servicecategory",
     *     MenuRoot="admin/openservice.index",
     *     is_menu = 0
     * )
     */
    public function addservice()
    {
        $this->add(url('admin/openservice.servicecategory/index'));
        return $this->fetch();
    }

    /**
     * @NodeAnnotation(
     *     title="修改开放服务",
     *     parent="admin/openservice.servicecategory",
     *     MenuRoot="admin/openservice.index",
     *     is_menu = 0
     * )
     */
    public function saveservice($id=0)
    {
        $this->edit(url('admin/openservice.servicecategory/index'));

        $this->assign([
            "service" => $this->model->find($id)
        ]);
        return $this->fetch();
    }

    /**
     * @NodeAnnotation(
     *     title="删除开放服务",
     *     parent="admin/openservice.servicecategory",
     *     MenuRoot="admin/openservice.index",
     *     is_menu = 0
     * )
     */
    public function delservice()
    {
        $this->del();
    }
}